package com.example.Views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import functions.barcode_gen;
import functions.item;

import java.util.ArrayList;

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    functions.Home home_fct;

    public MyActivity() {
        home_fct = new functions.Home(this);

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void new_item(View view) {
        setContentView(R.layout.new_item);
    }

    /* When "add product clicked" */
    public void add_prd(View view) {
        String SKU;
        String Name;
        Integer Stock;
        item myitem;

        //Get data from view
        Name = ((EditText)findViewById(R.id.editText)).getText().toString();
        SKU = ((EditText)findViewById(R.id.editText1)).getText().toString();
        Stock = Integer.parseInt(((EditText) findViewById(R.id.editText2)).getText().toString());
        //Call the controller function
        myitem = home_fct.new_item(SKU, Name, Stock);
        /*Intent nextScreen = new Intent(getApplicationContext(), barcode_gen.class);
        nextScreen.putExtra("product_sku",myitem.getSku());
        startActivity(nextScreen);
        */

    }

    public void see_all(View view){
        ListView lv;
        ArrayList  myitems;
        myitems = home_fct.show_all();


        setContentView(R.layout.show_all);

        lv = (ListView) findViewById(R.id.listView);
        ArrayAdapter<String> arrayAdapter;
        arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myitems);
        lv.setAdapter(arrayAdapter);

    }
}
